﻿using Gma.QrCodeNet.Encoding;
using Gma.QrCodeNet.Encoding.Windows.Render;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace TjZheng.Example.MVC.Controllers
{
    public class QrCodeController : Controller
    {
        public ActionResult Index()
        {
            QrEncoder encoder = new QrEncoder();
            QrCode qrCode = encoder.Encode("http://www.cnblogs.com/huangxincheng/archive/2012/02/18/2356595.html");
            GraphicsRenderer gRender = new GraphicsRenderer(new FixedModuleSize(5, QuietZoneModules.Four));
            BitMatrix matrix = qrCode.Matrix;
            using (MemoryStream stream = new MemoryStream())
            {
                gRender.WriteToStream(matrix, ImageFormat.Png, stream);

                return File(stream.ToArray(), "image/png");
            }
        }

    }
}
